<?php
$result = null;
$Gmac = GetMacAddr();

$con = mysql_connect("localhost", "root", "bytewalla5") or die(mysql_error());
if (!$con) {
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("wsn", $con);

$result = mysql_query("select * from gateway where gateway_mac_addr = '" . $Gmac ."' ");
if (mysql_num_rows($result)) {
	$myrow1 = mysql_fetch_array($result);
	$gateway_name = $myrow1['gateway_name'];
	$gateway_mac_addr = $myrow1['gateway_mac_addr'];
	$location = $myrow1['location'];
	mysql_close($con);
} else {
	$result = mysql_query("insert into gateway(gateway_mac_addr) values ('" . $Gmac . "')");
	mysql_close($con);
	header("Location: updateGatewayInfo.php");
}

function GetMacAddr() {
	@ exec("/sbin/ifconfig -a", $return_array);
	$temp_array = array ();
	foreach ($return_array as $value) {
		if (preg_match("/[0-9a-f][0-9a-f][:-]" .
			"[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f]/i", $value, $temp_array)) {
			$mac_addr = $temp_array[0];
			break;
		}

	}
	unset ($temp_array);
	return $mac_addr;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<title>Gateway Manage</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.6.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Swis721_Cn_BT_400.font.js"></script>
<script type="text/javascript" src="js/Swis721_Cn_BT_700.font.js"></script>
<script type="text/javascript" src="js/tabs.js"></script>
<!--[if lt IE 9]>
  	<script type="text/javascript" src="js/html5.js"></script>
	<style type="text/css">
		.bg{ behavior: url(js/PIE.htc); }
	</style>
<![endif]-->
<!--[if lt IE 7]>
		<div style=' clear: both; text-align:center; position: relative;'>
			<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"><img src="http://www.theie6countdown.com/images/upgrade.jpg" border="0"  alt="" /></a>
		</div>
<![endif]-->
</head>
<body id="page5">
	<div class="body1">
	<div class="body2">
	<div class="body5">
		<div class="main">
<!-- header -->
			<?php include("wsnheader.html"); ?>
<!-- header end-->
		</div>
	</div>
	</div>
	</div>
	<div class="body3">
		<div class="main">
<!-- content -->
			<article id="content">
				<div class="wrapper">
					<section class="col1">
						<h2 class="under">Gateway Management</h2>
						<form id="ContactForm" method="post">
						<div>
							<div  class="wrapper">
								<span>Name:</span><?php echo $gateway_name; ?>
								
							</div>
							
							<div  class="wrapper">
								<span>Mac-Addr:</span><?php echo $Gmac; ?>
								
							</div>
							<div  class="wrapper">
								<span>Location:</span><?php echo $location; ?>
								<br/><br/>
								<a href="updateGatewayInfo.php" >Modify</a>
								<a href="sunspotlist.php">show sunspot</a>
							</div>
							
							
						</div>
					</form>
					</section>
					
				</div>

			</article>
		</div>
	</div>
	
<!-- content end -->
<!-- footer -->
			<?php include("footer.html"); ?>
<!-- footer end -->
<script type="text/javascript"> Cufon.now(); </script>
<script>
	$(document).ready(function() {
		tabs.init();
	})
</script>
</body>
</html>	